<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="script/jquery-1.10.min.js">
// <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<!-- <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"> -->
<link rel="stylesheet" href="script/bootstrap-3.3.7.min.css">
<!-- <script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script> -->
<script src="script/bootstrap-3.3.7.min.js"></script>
<script src="script/bootstrap-3.3.7.min.js"></script>
<script src="script/bootbox.min.js"></script>
</script>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-md-6">
        <table class="table">
          <thead>
            <th></th>
            <th>用户名</th>
            <th>电话</th>
            <th>性别</th>
          </thead>
          <tbody>
            <tr>
            <td><input type="checkbox" value="1" name="3"></td>
            <td><input type="text" name="user" reg="^\w{6,8}" tip="用户名少于8位"></td>
            <td><input type="text" name="tel" reg="^\d{6,8}" tip="电话少于8位"></td>
            <td>男</td>
            </tr>
            <tr>
          </tbody>

        </table>

      </div>

    </div>
    <div class="row">
      <button class="btn btn-info" onclick="ok()"> 提交</button>


    </div>
  </div>
</body>

<script type="text/javascript">
function ok(){

var str="Hello world!";
//查找"Hello"
var patt=/\w{4,120}/;
var result=patt.test(str);
var result1=patt.exec(str); //匹配不到 返回null
console.log(result); //true or false
console.log(result1,result1[0],result1.index,result1.input) 
//匹配的文本 ["Hello", index: 0, input: "Hello world!"]

var patt1= /\d{1,2}/
console.log( (patt1.exec(str)) == null )


  $("td input[name=user]").each(function(index, el) {
    var v = $(this).val()
    var r = $(this).attr("reg")
    var t = $(this).attr("tip")
    var reg = new RegExp(r)
    console.log(reg.test(v))  //字符串 转 正则对象
    if (!reg.test(v)){
      bootbox.alert(t)
    }
  })
  $("td input[name=tel]").each(function(index, el) {
    var v = $(this).val()
    var r = $(this).attr("reg")
    var t = $(this).attr("tip")
    var reg = new RegExp(r)
    console.log(reg.test(v))
    if (!reg.test(v)){
      bootbox.alert(t)
    }
  });


};

</script>
</html>
